﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SASS.Sociales.BE;
using SASS.Sociales.BLL;
using SASS.Sociales.Util;

public partial class act_editar : BasePage
{
    
    #region "Iniciar Pagina"
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            txtCodigoActorHidden.Value = "1";
            CargarDatos();            
        }
    }

    #endregion

    #region "Cargar Datos"

    private void CargarDatos() {

        this.Master.TituloPagina = this.TituloPaginaActual();

        ActorBE oActor = new ActorBE();
        ActorBL oActorBL = new ActorBL();
        oActor = oActorBL.Obtener_Actor_SELPK(txtCodigoActorHidden.Value);

        txtCodigoActorHidden.Value = Convert.ToString(oActor.Codigo);
        txtNombre.Text = oActor.Nombre;
        txtRazonSocial.Text = oActor.RazonSocial;
        txtRUC.Text = oActor.Ruc;
        txtDireccion.Text = oActor.Direccion;
        txtDescripcion.Text = oActor.Descripcion;
        txtTelefono.Text = oActor.Telefono;
        txtEmail.Text = oActor.Email;
        txtWebSite.Text = oActor.Website;

    }

    #endregion

    #region "Funciones"

    private bool Guardar() {

        bool exito = false;
        ActorBE oActor = new ActorBE();
        ActorBL oActorBL = new ActorBL();

        oActor.Codigo = Convert.ToInt32(txtCodigoActorHidden.Value);
        oActor.Nombre = txtNombre.Text;
        oActor.RazonSocial = txtRazonSocial.Text;
        oActor.Rubro = "001"; //ddlRubro.SelectedItem.Value;
        oActor.Descripcion = txtDescripcion.Text;
        oActor.Ruc = txtRUC.Text;
        oActor.Ubigeo = "33";
        oActor.Direccion = txtDireccion.Text;        
        oActor.Telefono = txtTelefono.Text;
        oActor.Email = txtEmail.Text;
        oActor.Website = txtWebSite.Text;
        oActor.TipoEntidad = "001";

        if (txtAccionHidden.Value == Constantes.SIAS_ACCION_NUEVO)
        {
            exito = oActorBL.Insertar_SIASS_Actor(oActor);
        }
        else {
            exito = oActorBL.Actualizar_SIASS_Actor(oActor);
        }
        return exito;
        
    }

    #endregion

    #region "Eventos de Controles"

    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        if (Guardar()) {
            txtAccionHidden.Value = Constantes.SIAS_ACCION_EDITAR;
        }
    }

    #endregion
}